package com.atguigu.gulimall.member.web;

import com.alibaba.fastjson.TypeReference;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.member.feign.OrderFeignService;
import com.atguigu.gulimall.member.to.OrderTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;


@Controller
public class MemberWebController {
    @Autowired
    OrderFeignService orderFeignService;
    @GetMapping("/orderList.html")
    public String orderList(Model model){
        //查询当前用户的所有订单
        R r= orderFeignService.memberOrders();
        if(r.getCode()==0){
            List<OrderTo> data = r.getData(new TypeReference<List<OrderTo>>() {
            });
            model.addAttribute("orders",data);
            return "index";
        }
        return "redirect:http://www.gulimall.com";
    }
}
